import {CliInternals} from '@remotion/cli';
import {packages} from '@remotion/studio-shared';
import {expect, test} from 'bun:test';
import {CreateVideoInternals} from 'create-video';
import {writeFileSync} from 'node:fs';
import path from 'node:path';

test('create-video and cli should have the same list of packages', () => {
	const list1 = path.resolve(
		__dirname,
		'..',
		'..',
		'..',
		'create-video',
		'src',
		'list-of-remotion-packages.ts',
	);
	const list2 = path.resolve(
		__dirname,
		'..',
		'..',
		'..',
		'cli',
		'src',
		'list-of-remotion-packages.ts',
	);
	const contents =
		[
			'// Generated by package-sync.test.ts',
			'export const listOfRemotionPackages = [',
			...packages
				.map((p) => (p === 'core' ? 'remotion' : `@remotion/${p}`))
				.map((p) => `\t'${p}',`),
			'];',
		].join('\n') + '\n';

	writeFileSync(list1, contents);
	writeFileSync(list2, contents);

	expect(CreateVideoInternals.listOfRemotionPackages).toEqual(
		CliInternals.listOfRemotionPackages,
	);
});
